﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Emeny : MonoBehaviour {

    public float speed;
    private Transform playerPos;

    private Player player;

	// Use this for initialization
	void Start () {

        playerPos = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();


	}
	
	// Update is called once per frame
	void Update () {

        transform.position = Vector2.MoveTowards(transform.position,playerPos.position,speed*Time.deltaTime);




	}

	private void OnTriggerEnter2D(Collider2D collision)
	{
        if(collision.CompareTag("Player")){

            player.health--;
            Destroy(gameObject);
        }


        if(collision.CompareTag("Buttle")){

            Destroy(gameObject);
        }
	}
}
